package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("/users")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 获取用户信息
     * @param userID
     * @param huanxinID
     * @return
     */
    @GetMapping
    public ResponseEntity getUserInfo(@RequestParam(required = false) Long userID,
                                      @RequestParam(required = false) Long huanxinID){
        UserInfoVo vo = userInfoService.getUserInfo(userID, huanxinID);
        return ResponseEntity.ok(vo);
    }

    /**
     * 用户资料 更新
     * @param vo
     * @return
     */
    @PutMapping
    public ResponseEntity updateUserInfo(@RequestBody UserInfoVo vo){
        userInfoService.updateUserInfo(vo);
        return ResponseEntity.ok(null);
    }

    /**
     * 后续功能由同学们独自实现
     * 在这里我们只做： 记录登录用户最后一次查看访客列表的时间
     * 互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表
     * 1 互相关注
     * 2 我关注
     * 3 粉丝
     * 4 谁看过我
     */
    @GetMapping("/friends/{type}")
    public ResponseEntity myList(@PathVariable int type, Long page,
                                 @RequestParam(required = false) Long pagesize,
                                 @RequestParam(required = false) String nickname){
        // 记录用户查看 访客列表的时间
        userInfoService.recordDate(type);
        return ResponseEntity.ok(new PageResult<Object>(page,pagesize,0l,new ArrayList<>()));
    }
}
